<!--会议室管理-->
<template>
	<el-card>
		<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item class="form-button-right">
				<el-button v-auth="'chamber:chamber:save'" type="primary" @click="addOrUpdateHandle()">新增会议室</el-button>
			</el-form-item>

			<el-form-item label="会议室状态">
				<el-tree-select
					v-model="state.queryForm.stateId"
					:data="stateList"
					value-key="id"
					check-strictly
					clearable
					:render-after-expand="false"
					:props="{ value: 'code', label: 'name', children: 'children' }"
					placeholder="请选择"
				>
				</el-tree-select>
			</el-form-item>
			<el-form-item>
				<KeyQuery v-model="state.queryForm.keyword" @getDataList="getDataList()" />
			</el-form-item>
		</el-form>

		<el-table v-loading="state.dataListLoading" :data="state.dataList" border style="width: 100%" @selection-change="selectionChangeHandle">
			<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
			<el-table-column prop="id" label="主键" header-align="center" align="center" v-if="false"></el-table-column>

			<el-table-column prop="imgUrl" label="会议室图片" header-align="center" align="center">
				<template #default="scope">
					<el-image :src="scope.row.imgUrl" style="width: 50px; height: 50px">
						<template #error>
							<div class="image-slot">
								<!-- /*图片加载失败显示的内容*/ -->
								<img src="@/assets/R-C.jpg" />
							</div>
						</template>
					</el-image>
				</template>
			</el-table-column>
			<el-table-column prop="name" label="会议室名称" header-align="center" align="center"></el-table-column>
			<el-table-column prop="name" label="会议室状态" header-align="center" align="center"></el-table-column>

			<el-table-column prop="maxNumber" label="最多容纳人数" header-align="center" align="center"></el-table-column>
			<el-table-column prop="siteId" label="所在工作地点" header-align="center" align="center"></el-table-column>
			<el-table-column prop="cityStr" label="所在工作城市" header-align="center" align="center"></el-table-column>
			<el-table-column prop="equipment" label="设备" header-align="center" align="center"></el-table-column>

			<el-table-column prop="isReserve" label="是否允许预定" header-align="center" align="center"></el-table-column>
			<el-table-column prop="remark" label="备注" header-align="center" align="center"></el-table-column>

			<el-table-column label="操作" fixed="right" header-align="center" align="center" width="200">
				<template #default="scope">
					<el-button v-auth="'chamber:chamber:update'" type="primary" link @click="addOrUpdateHandle(scope.row.id)">查看详情</el-button>
					<el-button v-auth="'chamber:chamber:update'" type="primary" link @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
					<el-button v-auth="'chamber:chamber:delete'" type="primary" link @click="deleteBatchHandle(scope.row.id)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
			:current-page="state.page"
			:page-sizes="state.pageSizes"
			:page-size="state.limit"
			:total="state.total"
			layout="total, sizes, prev, pager, next, jumper"
			@size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"
		>
		</el-pagination>

		<!-- 弹窗, 新增 / 修改 -->
		<add-or-update ref="addOrUpdateRef" @refreshDataList="getDataList"></add-or-update>
	</el-card>
</template>

<script setup lang="ts" name="ChamberIndex">
import { useCrud } from '@/hooks'
import { Ref, reactive, ref } from 'vue'
import { IHooksOptions } from '@/hooks/interface'
import { findListByDictId } from '@/api/nb/business/dictionaries_subset'

import AddOrUpdate from './plane/chamber-a-u.vue'

const state: IHooksOptions = reactive({
	dataListUrl: '/nb/chamber/page',
	deleteUrl: '/nb/chamber',
	queryForm: {}
})

const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: number) => {
	addOrUpdateRef.value.init(id)
}

//列表树
const stateList = ref()
const getDictList = (code: String, list: Ref) => {
	findListByDictId({ params: { code: code } }).then(res => {
		list.value = res.data
		list.value.unshift({ code: '', name: '请选择' })
	})
}
getDictList('HuiYiShiZhuangTai', stateList)

const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, deleteBatchHandle } = useCrud(state)
</script>
